<?php

/**
 * Albireo Kernel
 *
 * @copyright  Copyright (c) 2010 Albireo Solutions
 * @package    Kernel
 */

namespace Albireo\Application;

use Nette\Object;

/**
 * TODO: need to change db entity according to this object
 */
class Application extends Object {

    /** @var int */
    private $id;

    /** @var string */
    private $url;

    /** @var string */
    private $name;

    /** @var string */
    private $publisher;

    /** @var string */
    private $altText;

    /** @var \DateTime */
    private $created;

    /** @var string */
    private $version;

    /** @var bool */
    private $system;

    /** @var bool */
    private $auto;
    
    /** @var string */
    private $title;

    /** @var array */
    private $translations;
    
    public function __construct($name = null, $url = null) {
        $this->setName($name);
        $this->setUrl($url);
    }
    
    public function getAuto() {
        return $this->auto;
    }

    public function setAuto($auto) {
        $this->auto = $auto;
    }
    
    public function setAltText($altText) {
        $this->altText = $altText;
    }

    public function getAltText() {
        return $this->altText;
    }

    public function setCreated(\DateTime $created = null) {
        $this->created = $created;
    }

    public function getCreated() {
        return $this->created;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function getId() {
        return $this->id;
    }

    public function setName($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }

    public function setPublisher($publisher) {
        $this->publisher = $publisher;
    }

    public function getPublisher() {
        return $this->publisher;
    }

    public function setUrl($url) {
        if (substr($url, 0, 1) == '/') {
            $url = $_SERVER['SERVER_NAME'] . $url;
        }
        $this->url = $url;
    }

    public function getUrl() {
        return $this->url;
    }

    public function setVersion($version) {
        $this->version = $version;
    }

    public function getVersion() {
        return $this->version;
    }

    public function setSystem($system) {
        $this->system = $system;
    }

    public function getSystem() {
        return $this->system;
    }
    
    public function getTitle() {
        return $this->title;
    }

    public function setTitle($title) {
        $this->title = $title;
    }

    public function getTranslations() {
        return $this->translations;
    }

    public function setTranslations(array $translations) {
        $this->translations = $translations;
    }

    
    public function encodeJSON() {
        $json = new \stdClass();
        foreach ($this as $key => $value) {
            $json->$key = $value;
        }
        return json_encode($json);
    }

}